<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="cpaNew" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['cpaNew']" placeholder="请输入cpaNew" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="customParameters" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['customParameters']" placeholder="请输入customParameters"></a-input>
        </a-form-item>
        <a-form-item label="failReason" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['failReason']" placeholder="请输入failReason"></a-input>
        </a-form-item>
        <a-form-item label="goodsId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['goodsId']" placeholder="请输入goodsId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="goodsName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['goodsName']" placeholder="请输入goodsName"></a-input>
        </a-form-item>
        <a-form-item label="goodsPrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['goodsPrice']" placeholder="请输入goodsPrice" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="goodsQuantity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['goodsQuantity']" placeholder="请输入goodsQuantity" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="goodsThumbnailUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['goodsThumbnailUrl']" rows="4" placeholder="请输入goodsThumbnailUrl"/>
        </a-form-item>
        <a-form-item label="orderAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderAmount']" placeholder="请输入orderAmount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderCreateTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderCreateTime']" placeholder="请输入orderCreateTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderGroupSuccessTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderGroupSuccessTime']" placeholder="请输入orderGroupSuccessTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderModifyAt" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderModifyAt']" placeholder="请输入orderModifyAt" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderPayTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderPayTime']" placeholder="请输入orderPayTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderSn" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['orderSn']" placeholder="请输入orderSn"></a-input>
        </a-form-item>
        <a-form-item label="orderStatus" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderStatus']" placeholder="请输入orderStatus" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderStatusDesc" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['orderStatusDesc']" placeholder="请输入orderStatusDesc"></a-input>
        </a-form-item>
        <a-form-item label="orderVerifyTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderVerifyTime']" placeholder="请输入orderVerifyTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="promotionAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['promotionAmount']" placeholder="请输入promotionAmount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="promotionRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['promotionRate']" placeholder="请输入promotionRate" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="pId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pId']" placeholder="请输入pId"></a-input>
        </a-form-item>
        <a-form-item label="type" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['type']" placeholder="请输入type" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="catIdsStr" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['catIdsStr']" placeholder="请输入catIdsStr"></a-input>
        </a-form-item>
        <a-form-item label="authDuoId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['authDuoId']" placeholder="请输入authDuoId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="batchNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['batchNo']" placeholder="请输入batchNo"></a-input>
        </a-form-item>
        <a-form-item label="groupId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['groupId']" placeholder="请输入groupId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderReceiveTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderReceiveTime']" placeholder="请输入orderReceiveTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderSettleTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['orderSettleTime']" placeholder="请输入orderSettleTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="zsDuoId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['zsDuoId']" placeholder="请输入zsDuoId" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'


  export default {
    name: "PddGoodsOrderModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/pdd/pddGoodsOrder/add",
          edit: "/pdd/pddGoodsOrder/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'cpaNew','customParameters','failReason','goodsId','goodsName','goodsPrice','goodsQuantity','goodsThumbnailUrl','orderAmount','orderCreateTime','orderGroupSuccessTime','orderModifyAt','orderPayTime','orderSn','orderStatus','orderStatusDesc','orderVerifyTime','promotionAmount','promotionRate','pId','type','catIdsStr','authDuoId','batchNo','groupId','orderReceiveTime','orderSettleTime','zsDuoId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'cpaNew','customParameters','failReason','goodsId','goodsName','goodsPrice','goodsQuantity','goodsThumbnailUrl','orderAmount','orderCreateTime','orderGroupSuccessTime','orderModifyAt','orderPayTime','orderSn','orderStatus','orderStatusDesc','orderVerifyTime','promotionAmount','promotionRate','pId','type','catIdsStr','authDuoId','batchNo','groupId','orderReceiveTime','orderSettleTime','zsDuoId'))
      },

      
    }
  }
</script>